package com.yk.mr.service.manage.impl;

import com.jcraft.jsch.JSchException;
import com.yk.mr.dao.common.api.ICommonDAO;
import com.yk.mr.model.job.JobModel;
import com.yk.mr.service.job.api.IJobService;
import com.yk.mr.service.manage.api.IJobManageService;
import com.yk.mr.service.manage.api.IJobSubmitService;
import org.springframework.stereotype.Service;


import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service("jobManageService")
public class JobManageServiceImpl implements IJobManageService {
    @Resource(name = "jobService")
    private IJobService jobService;
    @Resource(name = "commonDAO")
    private ICommonDAO commonDAO;
    @Resource(name = "jobSubmitService")
    private IJobSubmitService jobSubmitService;

    @Override
    public Map<String,Object> startJob(String jobId, String clusterId) throws JSchException {
        JobModel  model = this.jobService.getJobModel(jobId);
//        if (model!=null){
//            HashMap<String,Object> map=new HashMap<>();
//            map.put("jobName",model.getJobName());
//            map.put("jobType",model.getJobType());
//            map.put("jobParameters",model.getJobParameters());
//            map.put("submitId",model.getSubmissionId());
//            map.put("jobInput",model.getJobInput());
//            map.put("jobOutput",model.getJobOutput());
//            map.put("jarPath",model.getJarPath());
//            map.put("updateTime",model.getUpdateTime());
//            map.put("createTime",model.getCreateTime());
//        }
        model.setUpdateTime(new Timestamp(new Date().getTime()));
        this.commonDAO.update(model);
        return this.jobSubmitService.submitMRJob(model,clusterId);
    }

    @Override
    public Object stopJob(String jobId) {
        return null;
    }

    @Override
    public Object queryProcessState(String jobId) {
        return null;
    }
}
